﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace CMS_GYM
{
    class clsLichDAO
    {
        #region Attribute
        /// <summary>
        /// Kết nối SQL Server
        /// </summary>
        private CSQLServer sqlServer = new CSQLServer();
        #endregion

        /// <summary>
        /// Lấy danh sách chức năng
        /// </summary>
        public DataTable LayBang()
        {
            return new DataTable();
        }

        public DataTable KiemTraKhachHangVaSanCauTrongLich(clsLichDTO Lich)
        {
            DataTable dt = new DataTable();
            string sql = "sp_KiemTraKhachHangVaSanCauTrongLich";
            string[] ParameterColection = new string[2] { "@KhachHangId", "@SanCauId" };
            Object[] valueofParameter = new Object[2] { Lich.KhachHangId, Lich.SanCauId };
            dt = sqlServer.readData(sql, ParameterColection, valueofParameter);
            return dt;
        }

       /// Thêm chức năng
       /// </summary>
       /// <param name="ChucNang"></param>
       /// <returns></returns>
        public int Them(clsLichDTO Lich)
        {
            int i = -1;
            string sql = "sp_InsertLich";
            string[] ParameterColection = new string[4] { "@KhachHangId", "@SanCauId", "@NgayBatDau", "@NgayKetThuc" };
            Object[] valueofParameter = new Object[4] { Lich.KhachHangId, Lich.SanCauId, Lich.NgayBatDau, Lich.NgayKetThuc };

            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }

        /// <summary>
        /// Sửa thông tin chức năng
        /// </summary>
        /// <param name="Lich">
        /// MaChucNang  nvarchar(10)
        /// TenChucNang  nvarchar(255)
        /// </param>
        public int Sua(clsLichDTO Lich)
        {
            int i = -1;
            string sql = "sp_UpdateLich";
            string[] ParameterColection = new string[5];
            Object[] valueofParameter = new Object[5];

            ParameterColection[0] = "@LichId";
            valueofParameter[0] = Lich.LichId;
            ParameterColection[1] = "@KhachHangId";
            valueofParameter[1] = Lich.KhachHangId;
            ParameterColection[2] = "@SanCauId";
            valueofParameter[2] = Lich.SanCauId;
            ParameterColection[3] = "@TrangThai";
            valueofParameter[3] = Lich.TrangThai;
            ParameterColection[4] = "@IsLock";
            valueofParameter[4] = Lich.IsLock;
           
            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }

        /// <summary>
        /// Xóa chức năng
        /// </summary>
        /// <param name="MaChucNang">Mã chức năng</param>
        public int Xoa(int LichId)
        {
            int i = -1;
            string sql = "sp_DeleteLich";
            string[] ParameterColection = new string[1];
            Object[] valueofParameter = new Object[1];
            ParameterColection[0] = "@LichId";
            valueofParameter[0] = LichId;
            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }
    }
}
